package edu.gu.hajo.gcl.cmd.impl;

import edu.gu.hajo.gcl.exception.ExecException;
import edu.gu.hajo.gcl.interp.IInterpreter;
import edu.gu.hajo.gcl.script.Script;

/**
 * TODO a lot string true etc
 * @author hajo
 *
 */
public final class IfCmd extends AbstractCmd {
	
	public IfCmd(IInterpreter interp) {
		super(interp);
	}

	@Override
	public void execute() {
		
		if( args.size() != 2){
			throw new ExecException("If : wrong # args");
		}
		
		Script cond = new Script(args.get(0));
		interp.eval( cond );
		String result = interp.getResult();
		if( result.equals("true")){
			Script body = new Script(args.get(1));
			interp.eval(body);
			return;
		}
		interp.setResult("");
	}
}
